﻿@{
	Layout = null;
}
<link href="~/libs/layui-v2.9.21/layui/css/layui.css" rel="stylesheet" />
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>商品信息编辑</title>
	<style>
		body {
			font-family: Arial, sans-serif;
		}

		.container {
			width: 800px;
			margin: 0 auto;
			border: 1px solid #ccc;
			padding: 20px;
			box-shadow: 2px 2px 12px #aaa;
		}

		.header {
			border-bottom: 1px solid #ccc;
			padding-bottom: 10px;
			margin-bottom: 20px;
		}

		table {
			width: 100%;
			border-spacing: 15px;
		}

		th, td {
			text-align: left;
			padding: 5px;
		}

		th {
			color: red;
		}

		input[type="text"], select {
			width: 100%;
			padding: 6px 10px;
			margin: 4px 0;
			box-sizing: border-box;
		}

		.buttons {
			text-align: right;
		}

			.buttons input {
				padding: 8px 20px;
				margin: 10px;
				background-color: #007bff;
				color: white;
				border: none;
				cursor: pointer;
			}
	</style>
</head>
<body>
	<div class="container">
		<div class="header">
			<h2>商品信息</h2>
			<p>体积单位为立方米，重量单位为KG，保质期按天为单位</p>
		</div>
		<form class="layui-form" action="">
			<table>
				<input type="hidden" id="id" name="id" style="display:none">
				<tr>
					<th>所属货主</th>
					<td>
						<select name="belongsOwner">

							<option value="0">--zsx--</option>
							<option value="1">--yy--</option>
							<option value="2">--db--</option>
							<option value="3">--hc--</option>
							<option value="4">--dyw--</option>
						</select>
					</td>
					<th>产品大类</th>
					<td>
						<select name="productCategories">
							<option value="0">--电缆--</option>
							<option value="1">--恒温--</option>
							<option value="2">--常温--</option>
							<option value="3">--调温--</option>
						</select>
					</td>
				</tr>
				<tr>
					<th>产品属性</th>
					<td>
						<select name="productAttributes">
							<option value="0">--电缆--</option>
							<option value="1">--数码产品--</option>
							<option value="2">--日用--</option>
							<option value="3">--未知--</option>
						</select>
					</td>
					<th>价格</th>
					<td><input type="text" name="price"></td>
				</tr>
				<tr>
					<th>商品编码</th>
					<td><input type="text" name="productCode"></td>
					<th>客户商品编码</th>
					<td><input type="text" name="clientProductCode"></td>
				</tr>
				<tr>
					<th>商品条码</th>
					<td><input type="text" name="itemBarcode"></td>
					<th>商品规格</th>
					<td><input type="text" name="productSpecifications"></td>
				</tr>
				<tr>
					<th>商品品牌</th>
					<td><input type="text" name="productBranding"></td>
					<th>SKU</th>
					<td><input type="text" name="sKU"></td>
				</tr>
				<tr>
					<th>商品名称</th>
					<td colspan="3"><input type="text" name="productName"></td>
				</tr>
				<tr>
					<th>单位</th>
					<td>
						<select name="unit">
							<option value="0">--个--</option>
							<option value="1">--盒--</option>
							<option value="2">--只--</option>
							<option value="3">--枚--</option>
						</select>
					</td>
					<th>重量</th>
					<td><input type="text" name="weight" lay-verify="required|number"></td>
				</tr>
				<tr>
					<th>宽</th>
					<td><input type="text" name="wide" lay-verify="required|number"></td>
					<th>长</th>
					<td><input type="text" name="long" lay-verify="required|number"></td>
				</tr>
				<tr>
					<th>高</th>
					<td><input type="text" name="high" lay-verify="required|number"></td>
					<th>体积</th>
					<td><input type="text" name="volume" lay-verify="required|number"></td>
				</tr>
				<tr>
					<th>保质期</th>
					<td><input type="text" name="shelfLife" lay-verify="required|number"></td>
					<th>允收天数</th>
					<td><input type="text" name="acceptableDays" lay-verify="required|number"></td>
				</tr>
				<tr>
					<th>计费商品类</th>
					<td><select name="billableItems"><option value="0">计费嘛</option></select></td>
					<th>码盘单层数量</th>
					<td><input type="text" name="codeDiscNumber" lay-verify="required|number"></td>
				</tr>
				<tr>
					<th>拆零控制</th>
					<td>
						<div class="layui-form">
							<input type="radio" name="tearDownControl" value="1" title="是">
							<input type="radio" name="tearDownControl" value="2" title="否" checked>
							<input type="radio" name="tearDownControl" value="3" title="初始">
						</div>
					</td>
					<th>码盘层高</th>
					<td><input type="text" name="discLayerHeight" lay-verify="required|number"></td>
				</tr>
				<tr>
					<th>拆零数量</th>
					<td><input type="text" value="1" name="splitNumber" lay-verify="required|number"></td>
					@* <th>初始</th> *@
					@* 	<td><input type="text" name="" lay-verify="required|number"></td> *@
				</tr>
				<tr>
					<th>拆零单位</th>
					<td>
						<select name="splitUnits">
							<option value="0">--件--</option>
							<option value="1">--箱--</option>
							<option value="2">--个--</option>
							<option value="3">--桶--</option>
						</select>
					</td>
					<th>最小库存量</th>
					<td><input type="text" name="numLnventoryLevels" lay-verify="required|number"></td>
				</tr>
			</table>
			<div class="buttons">
				<input type="submit" value="确定" lay-submit lay-filter="update">
				<button type="button" class="layui-btn layui-btn-primary" onclick="closeDialog()">返回</button>
			</div>
		</form>
	</div>
</body>
</html>

<script src="~/libs/jquery/jquery.js"></script>
<script src="~/libs/layui-v2.9.21/layui/layui.js"></script>

<script>
		//关闭弹框
	function closeDialog() {
		var index = parent.layer.getFrameIndex(window.name);
		parent.layer.close(index);
	}

		$(function () {
		findInfo()
	})

		function findInfo() {
		$.ajax({
			url: "/ProductDetails/FindProductDetails",
			data: { id: @ViewBag.id},
			type: "get",
			datatype: "json",
			success: function (res) {
						$("#id").val(@ViewBag.id);


						$('input[name="productCode"]').val(res.productCode || '');
						$('input[name="productName"]').val(res.productName || '');
						$('input[name="sKU"]').val(res.sku || '');
						$('input[name="price"]').val(res.price || '');
						$('input[name="weight"]').val(res.weight || '');
						$('input[name="volume"]').val(res.volume || '');
						$('select[name="belongsOwner"]').val(res.belongsOwner);
						$('input[name="clientProductCode"]').val(res.clientProductCode || '');
						$('input[name="itemBarcode"]').val(res.itemBarcode || '');
						 layui.form.render("select");
						$('select[name="productCategories"]').val(res.productCategories );
						 layui.form.render("select");
						$('select[name="productAttributes"]').val(res.productAttributes );
						 layui.form.render("select");
						$('input[name="productSpecifications"]').val(res.productSpecifications || '');
						$('input[name="productBranding"]').val(res.productBranding || '');
						$('select[name="unit"]').val(res.unit );
						  layui.form.render("select");
						$('select[name="billableItems"]').val(res.billableItems );
							layui.form.render("select");
						$('input[name="long"]').val(res.long || '');
						$('input[name="wide"]').val(res.wide || '');
						$('input[name="high"]').val(res.high || '');
						$('input[name="shelfLife"]').val(res.shelfLife || '');
						$('input[name="acceptableDays"]').val(res.acceptableDays || '');
						$('input[name="numLnventoryLevels"]').val(res.numLnventoryLevels || '');
						$('input[name="codeDiscNumber"]').val(res.codeDiscNumber || '');
						$('input[name="discLayerHeight"]').val(res.discLayerHeight || '');
						console.log(res.tearDownControl);
						$('select[name="tearDownControl"]').val(res.tearDownControl);
						  layui.form.render("select");
						$('select[name="splitUnits"]').val(res.splitUnits );
						  layui.form.render("select");
						$('input[name="splitNumber"]').val(res.splitNumber || '');

						// 重新渲染Layui表单
						layui.form.render("select");
			}
		})
	}




	layui.use(['form'], function(){
			var form = layui.form;

		form.verify({
			required: function(value, item){
				if (!value.trim()) {
					return '该字段不能为空';
				}
			},
			number: function(value, item){
				if (!/^\d+$/.test(value)) {
					return '该字段必须为数字';
				}
			}
		});
			form.on('submit(update)', function(data){
				var field = data.field;
				var newId=@ViewBag.id;
				field.id=newId;
				// if(Object.values(field).some(value => !value.trim())) {
				// 	layer.msg('请填写所有必填字段');
				// 	return false;
				// }
				console.log(field)

				$.ajax({
					url: '/ProductDetails/UpdateProductDetails',
					data: field,
					type: 'post',
					dataType: 'json',
					success: function(res){
						if(res == 1){
							alert('修改成功');
							closeDialog();
						} else {
							alert('修改失败');
						}
					},
					error: function() {
						alert('请求失败');
					}
				});
				return false;
			});
		});

</script>





